package com.basil.gym.exception;

import com.basil.gym.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.error("服务器出错：" + e.getMessage());
    }

    //自定义异常
    @ExceptionHandler(BasilException.class)
    @ResponseBody
    public Result error(BasilException e) {
        e.printStackTrace();
        return Result.error("错误：" + e.getMessage());
    }
}
